<?php
class EmailCommon {
	/**
	 * @param string $address 收件人地址
	 * @param string $body 发送内容
	 * @param string $title 发送标题
	 * @param array  $senderInfo 发件人地址
	 */
	function SendMail($address,$message,$title,$senderInfo='') {
	
		//获取email数据
		$ms = model('Data')->lget('email');
	
		vendor('phpmailer.class#phpmailer');
	
		$mail = new PHPMailer();
	
		if(empty($senderInfo)) {
			$from = $ms['email_account']; //发件人地址
			$from_name = $ms['email_sender_name']; //发件人名称
		} else {
			$from = $senderInfo['email_account'];
			$from_name = $senderInfo['email_sender_name'];
		}
	
		if($ms['email_sendtype'] == 'smtp') {
			$mail->Mailer = 'smtp';
			$mail->Host = $ms['email_host']; //设置smtp服务器
			$mail->Port = $ms['email_port'];
			if($ms['email_ssl_encrypt'] == 'ssl') {
				$mail->SMTPSecure = 'ssl';
			}
			$mail->SMTPAuth = true;  //设置为'需要验证'
			//设置有户名和密码
			$mail->Username = $ms['email_account'];
			$mail->Password = $ms['email_password'];
		} else {
			$mail->Mailer = 'mail';
		}
		$mail->From = $from;
		$mail->FromName = $from_name;
		$mail->CharSet = 'UTF-8'; //设置邮件字符编码
		$mail->Encoding	= "base64";
	
		if(is_array($address)) {
			foreach ($address as $value) {
				$mail->AddAddress($value);
			}
		} else {
			$mail->AddAddress($address);
		}
	
		$mail->IsHTML(true); // 是否使用HTML格式
		$mail->Body = $message; //设置邮件正文
		$mail->Subject = $title;   //设置邮件标题
		$mail->AltBody = "text/html"; //内容格式
		return($mail->Send());
	}
}
?>